#include "CyRoutine.h"

wregex CyRoutine::REGEX_INT(L"[+-]?\\d+");
wregex CyRoutine::REGEX_POS_INT(L"[+]?\\d+");
wregex CyRoutine::REGEX_FLOAT(L"[-+]?\d+(\.\d+)?");
wregex CyRoutine::REGEX_POS_FLOAT(L"[+]?\d+(\.\d+)?");

CyRoutine::CyRoutine(void)
{
}


CyRoutine::~CyRoutine(void)
{
}

bool CyRoutine::IsInteger(const wstring& num)
{
	return std::regex_match(num, REGEX_INT);
}

bool CyRoutine::IsPositiveInteger(const wstring& num)
{
	return std::regex_match(num, REGEX_POS_INT);
}

bool CyRoutine::IsFloatingPoint(const wstring& num)
{
	return std::regex_match(num, REGEX_FLOAT);
}

bool CyRoutine::IsPositiveFloatingPoint(const wstring& num)
{
	return std::regex_match(num, REGEX_POS_FLOAT);
}

bool CyRoutine::IsInteger(const wchar_t * num)
{
	return std::regex_match(num, REGEX_INT);
}

bool CyRoutine::IsPositiveInteger(const wchar_t * num)
{
	return std::regex_match(num, REGEX_POS_INT);
}

bool CyRoutine::IsFloatingPoint(const wchar_t * num)
{
	return std::regex_match(num, REGEX_FLOAT);
}

bool CyRoutine::IsPositiveFloatingPoint(const wchar_t * num)
{
	return std::regex_match(num, REGEX_POS_FLOAT);
}

int CyRoutine::GetInt(const wstring& num)
{
	if (!IsInteger(num))
	{
		char buffer[100];
		sprintf_s(buffer, 100,
			__FILE__ " : line %d : Not an integer", __LINE__);
	}
	return _wtoi(num.c_str());
}

long long CyRoutine::GetLongLong(const wstring& num)
{
	if (!IsInteger(num))
	{
		char buffer[100];
		sprintf_s(buffer, 100,
			__FILE__ " : line %d : Not an integer", __LINE__);
	}
	return _wtoi64(num.c_str());
}

float CyRoutine::GetFloat(const wstring& num)
{
	if (!IsInteger(num))
	{
		char buffer[100];
		sprintf_s(buffer, 100,
			__FILE__ " : line %d : Not a decimal number", __LINE__);
	}
	return _wtoi64(num.c_str());
}

double CyRoutine::GetDouble(const wstring& num)
{
	if (!IsInteger(num))
	{
		char buffer[100];
		sprintf_s(buffer, 100,
			__FILE__ " : line %d : Not a decimal number", __LINE__);
	}
	return _wtoi64(num.c_str());
}

int CyRoutine::GetInt(const wchar_t * num)
{
	if (!IsInteger(num))
	{
		char buffer[100];
		sprintf_s(buffer, 100,
			__FILE__ " : line %d : Not an integer", __LINE__);
	}
	return _wtoi(num);
}

long long CyRoutine::GetLongLong(const wchar_t * num)
{
	if (!IsInteger(num))
	{
		char buffer[100];
		sprintf_s(buffer, 100,
			__FILE__ " : line %d : Not an integer", __LINE__);
	}
	return _wtoi64(num);
}

float CyRoutine::GetFloat(const wchar_t * num)
{
	if (!IsInteger(num))
	{
		char buffer[100];
		sprintf_s(buffer, 100,
			__FILE__ " : line %d : Not a decimal number", __LINE__);
	}
	return _wtoi64(num);
}

double CyRoutine::GetDouble(const wchar_t * num)
{
	if (!IsInteger(num))
	{
		char buffer[100];
		sprintf_s(buffer, 100,
			__FILE__ " : line %d : Not a decimal number", __LINE__);
	}
	return _wtoi64(num);
}